if(z==null) var z=new Object();

z.tabs=function (hid,bid,howdo,css,fun){
	var $hd=$(hid),$bd=$(bid),fun=fun||function (){},css=css||"cur",arCss=function (id){
		id.addClass(css).siblings("."+css).removeClass(css);
	};
	$hd.bind(howdo=="click"?"click":"mouseover",function (){
		arCss($(this));
		if(bid) arCss($bd.eq($(this).index()));
		fun($(this));
		if(howdo=="click") return false;
	});	
};

z.setHomepage=function (url) {
	url = url||"http://" + document.location.host;
	if(!window.confirm("是否设置" + url + "为首页?")) return false;
	if (window.sidebar)
	{
		try { 
		   netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); 
		} 
		catch (e) 
		{  
		   alert("此操作被浏览器拒绝！\n请在浏览器地址栏输入\"about:config\"并回车\n然后将[signed.applets.codebase_principal_support]设置为'true'"); 
		} 
		var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);
		prefs.setCharPref('browser.startup.homepage','http://'+document.location.host);
	}
};

z.addFavorite=function (url,title) {   
	url = url||window.location.href;

	title = title||document.title;	
	if(window.ActiveXObject){
		window.external.addFavorite(url,title);
	}
	else {
		window.sidebar.addPanel(title,url,""); 
	}
};

z.focusPlayer=function(w,c,time){
		var $w=$(w),$c=$w.find(c),l=$c.length,ol="<ol><li class='current'>1</li>",t=time||6,t=t*1000;
		if(l>1){for(i=2;i<=l;i++){ol+="<li>"+i+"</li>";}};
		ol+="</ol>";
		$w.append(ol);
		var o=$w.find("ol li"),current;
		function play(i){
			$c.stop(true,true);
			$c.eq(i).fadeIn("normal").siblings(c).fadeOut("fast");
			o.eq(i).addClass("current").siblings().removeClass("current");
			current = ++i;
			}
		(autoPlay=function(){
			   playIng = setInterval(function() {if (current == null) {current = 1;} else if (current ==l) {current = 0;}
			   play(current);
				   },t);
			})();
		o.each(function(i){$(this).hover(function(){clearInterval(playIng);play(i)},function(){autoPlay();});});	
	}
	
function rePadding(f,t){
	$(f).each(function (){
		var $t=$(this).children(t),h=Math.round(($(this).height() - $t.height()) / 2);
		$t.css({
			paddingTop:h,
			paddingBottom:h
		});
	});
}

function scrollTop(id,height,time){
	var leng=id.children(":first").outerHeight(true),time=time||300;
	id.animate({marginTop:"-="+leng},time,function (){
		-parseInt(id.css("marginTop"))>=height&&id.css("marginTop",0);
	});	
}

function pushDown(id,time){
	var id=id||"#pushDown",$id=$(id),time=time||6000;
	$id.length>0&&setTimeout(function (){
		$id.animate({height:-parseFloat($id.css("marginTop"))},"slow",function (){
			$id.fadeOut("normal");
		});
	},time);
}

function divshow(id,fid,time){
	var id=id,fid=fid||"#pushDown",$id=$(id),$fid=$(fid),time=time||6000;
	$fid.hover(function(){
				$id.show();	
			},
			function()
			{
			    $id.hide(); 
				setTimeout($id,time);
			});
	}


$(function (){
			
			pushDown();
			$("ul.eshop>li:odd").addClass("f-r");
		
			function homeHover(id,over,out){
				id.hover(function (){
					eval(over);
				},function (){
					eval(out);
				});
			}
			
			csc.foucsPlay("div.index_slide");
			csc.search();
						
			csc.tabs("div.head-search>ul>li",null,"click",null,function (w){
		var input=w.closest(".head-search").find("form");
		switch(w.index()){
			case 1:
			document.search_frmhead.action= "company/list.php"; 			
			break;
			case 2:
			document.search_frmhead.action= "offer/list.php"; 			
			break;
			case 3:
			document.search_frmhead.action= "news/list.php"; 			
			break;
			default:
			document.search_frmhead.action= "product/list.php"; 			
		}});
		     			
			divshow("#headSel","#headSlected");
			divshow("#headSel","#headSel");		
			csc.tabs("div.search-type>ul>li",null,"click",null,function (w){
		var input=w.closest(".new-head").find("form");
		switch(w.index()){
			case 1:
			document.searchform.action= "company/list.php";
			$("#headSlected>a").text('公司');			
			break;
			case 2:
			document.searchform.action= "offer/list.php"; 
			$("#headSlected>a").text('求购');		
			break;
			case 3:
			document.searchform.action= "news/list.php";
			$("#headSlected>a").text('资讯');						
			break;
			default:
			document.searchform.action= "product/list.php";
			$("#headSlected>a").text('产品');	 			
		}});
		    
			
			var $sell=$("div.sell-buy>div.bd ul.s"),$buy=$("div.sell-buy>div.bd ul.b"),sH=$sell.height(),bH=$buy.height(),sSL,sBY;
			$sell.children(":lt(5)").clone().appendTo($sell);
			$buy.children(":lt(5)").clone().appendTo($buy);
			function sellBuy(){
				!sSL&&scrollTop($sell,sH);
				!sBY&&scrollTop($buy,bH);
				setTimeout(sellBuy,2500);
			}
			setTimeout(sellBuy,2500);
			homeHover($sell,"sSL=true","sSL=null");
			homeHover($buy,"sBY=true","sBY=null");			
																		 
		});

